package org.saratogaschools.edd.firefighter.client.activity;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class CheckInView extends Composite {
	
	public interface Presenter {

		void checkIn();

		void checkOut();

		void back();
		
	}

	private static CheckInViewUiBinder uiBinder = GWT
			.create(CheckInViewUiBinder.class);

	interface CheckInViewUiBinder extends UiBinder<Widget, CheckInView> {
	}
	
	private Presenter presenter;
	
	@UiField
	Label statusLabel;
	
	@UiField
	Button toggleStatusButton;
	
	@UiField
	Button backButton;

	public CheckInView() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}

	public void setCheckedIn(boolean checkedIn) {
		if (checkedIn) {
			statusLabel.setText("You are checked in.");
			toggleStatusButton.setText("Check out");
		}
		else {
			statusLabel.setText("You are not checked in.");
			toggleStatusButton.setText("Check in");
		}
	}
	
	@UiHandler("toggleStatusButton")
	void onButtonClicked(ClickEvent evt) {
		toggleStatusButton.setEnabled(false);
		if ("Check in".equals(toggleStatusButton.getText())) {
			presenter.checkIn();
		}
		else {
			presenter.checkOut();
		}
	}
	
	@UiHandler("backButton")
	void onBackButtonClicked(ClickEvent evt) {
		presenter.back();
	}
	

}
